package cn.itcast.nems.base.web.controller.o;

import cn.itcast.ic.common.bean.Page;
import cn.itcast.nems.base.api.DiscountsApi;
import cn.itcast.nems.base.dto.DiscountsDTO;
import cn.itcast.nems.base.dto.DiscountsQueryDTO;
import cn.itcast.nems.common.PageQueryModel;
import cn.itcast.nems.common.web.vo.BasePageRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Objects;

@RestController
@RequestMapping("/o/discount")
public class EnrolDiscountController {
    @Autowired
    private DiscountsApi discountsApi ;
    /**
     * 产品-班级列表分页查询
     * @param queryParam 请求参数
     * @return 分页结果
     */
    @PostMapping("/page/list")
    public ResponseEntity<?> findPageList (@RequestBody BasePageRequest<DiscountsQueryDTO> queryParam){
        queryParam.convert();
        DiscountsQueryDTO queryDTO = Objects.nonNull(queryParam.getCondition())? queryParam.getCondition(): new DiscountsQueryDTO() ;
        PageQueryModel<DiscountsQueryDTO> queryModel =new PageQueryModel<>(queryParam.getPageNumber(),queryParam.getPageSize(),queryDTO) ;
        Page<DiscountsDTO> page  = discountsApi.findEnrolPageList(queryModel) ;
        return ResponseEntity.ok().body(page) ;
    }

    /**
     * 获取子优惠列表
     * @param parentId 父节点ID
     * @return 关联的优惠列表
     */
    @GetMapping("/{parent_id}/list")
    public ResponseEntity<?> findPageList (@PathVariable("parent_id") Integer parentId){
        List<DiscountsDTO> list  = discountsApi.findDiscountsByParentId(parentId) ;
        return ResponseEntity.ok().body(list) ;
    }

}
